CC=g++

AR=ar
ARFLAGS=-cvq

SERIAL_COMM_ROOT=../../comm_libs/serial_comm
SERIAL_COMM_LIB=$(SERIAL_COMM_ROOT)/lib
SERIAL_COMM_INC=$(SERIAL_COMM_ROOT)/include

INCS=-I$(SERIAL_COMM_INC)
LIBS=-L$(SERIAL_COMM_LIB)

CFLAGS=-c -Wall $(INCS)
LDFLAGS=$(INCS) $(LIBS) -lserialcomm
SOURCES=test.cpp
OBJECTS=$(SOURCES:.cpp=.o)
LIB_SOURCES=serial_comm.cpp
LIB_OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=test

all: $(SERIAL_COMM_LIB) $(SOURCES) $(EXECUTABLE)

$(SERIAL_COMM_LIB): $(SERIAL_COMM_ROOT)/$(LIB_SOURCES)
	make -C $(SERIAL_COMM_ROOT) lib

$(EXECUTABLE): $(OBJECTS)
	mkdir -p bin
	$(CC) -o bin/$@ $(OBJECTS) $(LDFLAGS)

%.o: %.cpp
	$(CC) $(CFLAGS) $< -o $@

clean:
	rm -rf *~ bin $(OBJECTS)
	make -C $(SERIAL_COMM_ROOT) clean

run:
	./bin/$(EXECUTABLE)
